<template>
	<view class="box">
		<!-- 空 -->
		<view class="none" v-if="list.length == 0">
			<view class="none-img f-w">
				<image src="https://jw.xzsw2021.com/static/big/icon_226@2x.png" mode=""></image>
			</view>
			<view class="f30 tr c666">暂时没有任何红包可领哦</view>
		</view>
		<!-- 列表 -->
		<view class="list" v-else>
			<view class="card flex" v-for="(item,index) of list" :key="index">
				<view class="left">
					<view class="price">￥<text class="f40 bold">{{item.packet_value}}</text></view>
					<view class="tj f24" v-if="item.packet_condition">满{{item.packet_condition}}可用</view>
					<view class="tj f24" v-else>不限</view>
				</view>

				<view class="right">
					<view class="one">{{item.packet_name}}</view>
					<!-- <view class="two f24">{{$u.timeFormat(item.create_time, 'yyyy-mm-dd')}}</view> -->
					<view class="two f24">{{item.create_time}}</view>
					<view class="three flex" @click="zhankai(index)">
						<view>
							<view class="desc" :class="item.is_gain == false?'hide-line':''">{{item.use_intro}}</view>
						</view>
						<view class="icon" v-if="item.is_gain.length>17">
							<image src="https://jw.xzsw2021.com/static/img/icon_62@2x.png" mode="" v-if="!item.look">
							</image>
							<image src="https://jw.xzsw2021.com/static/img/icon_63@2x.png" mode="" v-else></image>
						</view>
					</view>
					<!-- 立即领取 -->
				
					<view class="lingqu"  v-if="item.is_gain && item.is_receive == 0 && (item.packet_num == 0 || item.packet_num > item.get_num)"  @click="lingqu(item)">
						立即领取
					</view>
					<view class="lingqu" v-else >
						已领取
					</view>
				</view>
			</view>
		</view>
		<!--  -->

	</view>
</template>

<script>
	import {
		getPlatformRedApi,
		userReceiveRedApi
	} from '@/api/user.js'
	export default {
		data() {
			return {
				list: [],
			}
		},
		created() {
			this.redList()
		},
		methods: {
			redList() {
				getPlatformRedApi().then(res => {
					this.list=res.data
				}).catch(err => {

				})
			},
			lingqu(item) {
				let data = {
					red_packet_id: item.red_packet_id
				}
				uni.showLoading({
					mask:true
				})
				userReceiveRedApi(data).then(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.message
					})
					this.redList()
				}).catch(err => {

				})

			},

			// 红包说明
			goCord() {
				console.log('红包说明');
				uni.navigateTo({
					url: '/pages/user/myredbao/redbao-desc/redbao-desc'
				})
			},
			// 展开
			zhankai(index) {
				this.list[index].look = !this.list[index].look;
			},
			// 红包领取中心
			goCenter() {
				console.log('红包领取中心');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		.tab {
			height: 96rpx;
			padding: 0 100rpx;
		}

		.cord {
			padding: 30rpx;
			font-size: 26rpx;
			text-align: right;
			color: #F45E14;
		}

		.bgc {
			background-color: #F5F5F5;
		}

		.none {
			.none-img {
				margin: 148rpx auto 80rpx;
				width: 376rpx;
				height: 329rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.list {
			min-height: calc(100vh - 96rpx);
			background-color: #F5F5F5;
			padding: 20rpx 30rpx 30rpx;
			box-sizing: border-box;

			.card {
				position: relative;
				margin-bottom: 20rpx;
				width: 690rpx;
				// height: 186rpx;
				padding: 23rpx 28rpx 23rpx 0;
				background: #FFFFFF;
				border-radius: 10rpx;
				box-sizing: border-box;

				.left {
					flex-shrink: 0;
					width: 160rpx;
					height: 160rpx;
					border-right: 1rpx dashed #CCCCCC;
					text-align: center;
					color: #F83535;

					.price {
						margin-top: 28rpx;
					}

					.tj {
						margin-top: 6rpx;
						color: #666;
					}
				}

				.right {
					position: relative;
					flex: 1;
					padding-right: 30rpx;
					margin-left: 30rpx;
					font-size: 28rpx;

					.two {
						margin: 28rpx 0;
						color: #666;
					}

					.three {
						color: #999;
						font-size: 24rpx;
						overflow: hidden;

						.desc {
							flex: 1;
							width: 420rpx;
						}

						.icon {
							flex-shrink: 0;
							margin-left: 20rpx;
							width: 26rpx;
							height: 14rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}
					}

					.lingqu {
						position: absolute;
						right: 30rpx;
						top: 56rpx;
						width: 130rpx;
						height: 44rpx;
						line-height: 44rpx;
						text-align: center;
						background: #FFFFFF;
						border: 1rpx solid #F83535;
						border-radius: 22rpx;
						font-size: 26rpx;
						color: #F83535;
					}

					.get {
						border: 1rpx solid #ccc;
						color: #666;
					}
				}
			}
		}
	}
</style>
